#ifndef HEAD_H
#define HEAD_H
#include<iostream>
using namespace std;

struct node{
    node*nx;
    int data;
};


class stack{
private:
    int top;

    node*tail;
    node*head;
    int system;
    int number_Decimal;
public:
    stack();
    void init_stack();
    void show();
    ~stack();
};


stack::stack(){
    top=-1;
    head=tail=NULL;
    cout<<"input a  decimal number:";
    cin>>number_Decimal;
    cout<<endl<<"input system:";
    cin>>system;
    if(number_Decimal>0&&system>=2&&system<=9)
    {
        init_stack();
        show();
    }
}

void stack::init_stack(){
    head=tail=new node;
    tail->nx=NULL;

    node*cur;

    int num=number_Decimal;

    while(num){
        head->data=num%system;
        num=num/system;
        top++;

        cur=head;
        head=new node;
        head->nx=cur;
    }
}
void stack::show(){
    node*p=head;
    cout<<endl;
    while(p->nx!=NULL){
        p=p->nx;
        cout<<p->data<<"\t";
    }
}

stack::~stack(){
    node*p=head;
    while(head){
        p=head;
        head=head->nx;
        delete p;
    }
}

#endif // HEAD_H
